from collections import defaultdict

from common.mssql_helper import g_msql_inst
from common.utils import create_uuid

__author__ = "Ypf"
_date_ = "2019/8/15-13:39"

class Ddycbj(object):
    @staticmethod
    def get_dic(sql):
        # 获取相应的对比sql查询语句
        res_list1 = g_msql_inst.fetch_all(sql)
        res_list2 = g_msql_inst.fetch_all("select   ghdw  from k3_xsdd  where sjsj>(select convert(varchar(10),dateadd(month,-6,getdate()),23))")
        dic = defaultdict(dict)
        for (ghdw ,ywy,sl,ggxh) in res_list1:
            if ghdw not in res_list2:
                dic[ghdw] = [ghdw ,ywy,sl,ggxh]
        return dic

    @staticmethod
    def insert(db_insert_sql, dic, nowtime,ys):
        for key in dic:
            id = create_uuid()
            dic[key].append(nowtime + '-01')
            dic[key].append(id)
            dic[key].append(ys)
            value_tuple = tuple(dic[key])
            excuete_sql = db_insert_sql % value_tuple
            print(excuete_sql)
            g_msql_inst.db_excuete(excuete_sql)